package com.doeis.minaserver.module;

import com.doeis.minaserver.NettyServer;
import com.doeis.minaserver.container.BasicModule;
import com.doeis.minaserver.packet.InfoPacket;
import com.doeis.minaserver.session.ClientConnection;
import com.doeis.uwork.module.GroupMsgPacketRouter;
import com.doeis.uwork.module.MessagePacketRouter;
import com.doeis.uwork.module.PrivateMsgPacketRouter;
import com.doeis.uwork.module.SystemPacketRouter;
import com.doeis.uwork.packet.GroupMsgPacket;
import com.doeis.uwork.packet.MessagePacket;
import com.doeis.uwork.packet.PrivateMsgPacket;
import com.doeis.uwork.packet.SystemPacket;

/**
 * 分发数据包总路由器
 * **/
public class PacketRouter extends BasicModule {
	
	private MessagePacketRouter messageRouter ;
	private InfoPacketRouter infoPacketRouter ;
	private GroupMsgPacketRouter groupMsgPacketRouter ;
	private PrivateMsgPacketRouter privateMsgPacketRouter ;
	private SystemPacketRouter systemPacketRouter ;
	
	public PacketRouter() {
		super("Packet Router");
	}

	@Override
	public void initialize(NettyServer server) {
		this.server = server;	
		
		messageRouter = server.getMessagePacketRouter();
		infoPacketRouter = server.getInfoPacketRouter();
		groupMsgPacketRouter = server.getGroupMsgPacketRouter();
		privateMsgPacketRouter = server.getPrivateMsgPacketRouter();
		systemPacketRouter = server.getT(SystemPacketRouter.class);
	}
	
	public void route(ClientConnection fromConn, MessagePacket packet) {
		messageRouter.route(fromConn,packet);
	}

	public void route(ClientConnection clientConn, InfoPacket p) {
		infoPacketRouter.route(clientConn, p);
	}
	public void route(ClientConnection clientConn, GroupMsgPacket p) {
		groupMsgPacketRouter.route(clientConn, p);
	}
	public void route(ClientConnection clientConn, PrivateMsgPacket p) {
		privateMsgPacketRouter.route(clientConn, p);
	}
	public void route(ClientConnection fromConn, SystemPacket packet) {
		systemPacketRouter.route(fromConn,packet);
	}
	
}
